package com.itbaizhan.cxpt.controller;

import com.itbaizhan.cxpt.common.Result;
import com.itbaizhan.cxpt.mapper.FileUploadRecordMapper;
import com.itbaizhan.cxpt.service.PdfAnalyzeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/api")
public class PdfAnalyzeController {

    @Autowired
    private PdfAnalyzeService pdfAnalyzeService;


    /**
     * 文件上传
     * @param file
     * @return
     */
    @PostMapping("/analyze")
    public Result analyzePdf(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return Result.error("请选择要上传的文件");
        }
        if (!file.getContentType().equals("application/pdf")) {
            return Result.error(500,"请上传PDF文件");
        }
        return pdfAnalyzeService.analyzePdf(file);
    }

    /**
     * 文件解析
     * @param fileId
     * @return
     */
    @GetMapping("/analyze/{fileId}")
    public Result analyzeByFileId(@PathVariable String fileId) {
        return pdfAnalyzeService.analyzeByFileId(fileId);
    }

    /**
     * 分析已解析的文件
     */
    @GetMapping("/filerecords/analyze/{fileId}")
    public Result analyzeFileContent(@PathVariable String fileId) {
        return pdfAnalyzeService.analyzeFileContent(fileId);
    }
}